package com.shashidi.weather.base;

import android.content.Context;
import android.support.multidex.MultiDexApplication;

import com.gtdev5.geetolsdk.mylibrary.initialization.GeetolSDK;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class BaseApplication extends MultiDexApplication {

    public static Context mContext;
    private static BaseApplication appInstance;

    public static BaseApplication getInstance() {
        if (null == appInstance) {
            appInstance = new BaseApplication();
        }
        return appInstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        appInstance = this;
        //sdk
        GeetolSDK.init(this, "http://shashidi.weiapp8.cn/app/");
        //禁止小米弹窗
        disableAPIDialog();
    }

    /**
     * application里面 调用  反射 禁止弹窗 解决 detected problems with api  9.0手机（小米）
     */
    private void disableAPIDialog() {
        try {
            Class clazz = Class.forName("android.app.ActivityThread");
            Method currentActivityThread = clazz.getDeclaredMethod("currentActivityThread");
            currentActivityThread.setAccessible(true);
            Object activityThread = currentActivityThread.invoke(null);
            Field mHiddenApiWarningShown = clazz.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
